package com.fc.test.service;

import java.util.List;
import java.util.Arrays;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import cn.hutool.core.util.StrUtil;
import com.fc.test.common.base.BaseService;
import com.fc.test.common.support.ConvertUtil;
import com.fc.test.mapper.auto.ForeOrderMapper;
import com.fc.test.model.auto.ForeOrder;
import com.fc.test.model.auto.ForeOrderExample;
import com.fc.test.model.custom.Tablepar;
import com.fc.test.util.SnowflakeIdWorker;
import com.fc.test.util.StringUtils;

/**
 * 订单 ForeOrderService
 * @Title: ForeOrderService.java 
 * @Package com.fc.test.service 
 * @author fuce_自动生成
 * @email 115889198@qq.com
 * @date 2020-09-02 20:53:02  
 **/
@Service
public class ForeOrderService implements BaseService<ForeOrder, ForeOrderExample>{
	@Autowired
	private ForeOrderMapper foreOrderMapper;
	
      	   	      	      	      	      	      	      	      	      	      	      	      	
	/**
	 * 分页查询
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	 public PageInfo<ForeOrder> list(Tablepar tablepar,ForeOrder record){
	        ForeOrderExample testExample=new ForeOrderExample();
			//搜索
			if(StrUtil.isNotEmpty(tablepar.getSearchText())) {//小窗体
	        	testExample.createCriteria().andLikeQuery2(tablepar.getSearchText());
	        }else {//大搜索
	        	testExample.createCriteria().andLikeQuery(record);
	        }
			//表格排序
			if(StrUtil.isNotEmpty(tablepar.getOrderByColumn())) {
	        	testExample.setOrderByClause(StringUtils.toUnderScoreCase(tablepar.getOrderByColumn()) +" "+tablepar.getIsAsc());
	        }else{
	        	testExample.setOrderByClause("id ASC");
	        }
	        PageHelper.startPage(tablepar.getPageNum(), tablepar.getPageSize());
	        List<ForeOrder> list= foreOrderMapper.selectByExample(testExample);
	        PageInfo<ForeOrder> pageInfo = new PageInfo<ForeOrder>(list);
	        return  pageInfo;
	 }

	@Override
	public int deleteByPrimaryKey(String ids) {
				
			List<String> lista=ConvertUtil.toListStrArray(ids);
			ForeOrderExample example=new ForeOrderExample();
			example.createCriteria().andIdIn(lista);
			return foreOrderMapper.deleteByExample(example);
			
				
	}
	
	
	@Override
	public ForeOrder selectByPrimaryKey(String id) {
				
			return foreOrderMapper.selectByPrimaryKey(id);
				
	}

	
	@Override
	public int updateByPrimaryKeySelective(ForeOrder record) {
		return foreOrderMapper.updateByPrimaryKeySelective(record);
	}
	
	
	/**
	 * 添加
	 */
	@Override
	public int insertSelective(ForeOrder record) {
				
		//添加雪花主键id
		record.setId(SnowflakeIdWorker.getUUID());
			
				
		return foreOrderMapper.insertSelective(record);
	}
	
	
	@Override
	public int updateByExampleSelective(ForeOrder record, ForeOrderExample example) {
		
		return foreOrderMapper.updateByExampleSelective(record, example);
	}

	
	@Override
	public int updateByExample(ForeOrder record, ForeOrderExample example) {
		
		return foreOrderMapper.updateByExample(record, example);
	}

	@Override
	public List<ForeOrder> selectByExample(ForeOrderExample example) {
		
		return foreOrderMapper.selectByExample(example);
	}

	
	@Override
	public long countByExample(ForeOrderExample example) {
		
		return foreOrderMapper.countByExample(example);
	}

	
	@Override
	public int deleteByExample(ForeOrderExample example) {
		
		return foreOrderMapper.deleteByExample(example);
	}
	
	/**
	 * 检查name
	 * @param foreOrder
	 * @return
	 */
	public int checkNameUnique(ForeOrder foreOrder){
		ForeOrderExample example=new ForeOrderExample();
		example.createCriteria().andNameEqualTo(foreOrder.getName());
		List<ForeOrder> list=foreOrderMapper.selectByExample(example);
		return list.size();
	}


}
